/**	\file lsc_effect.c This file contains definitions for all functions and variables of the Left Scroll component.
*/
#include "lsc_effect.h"
#include "LOC_scrnframe.h"



/****************/
/*	Local Types */
/****************/







/*********************/
/*	Local Dfinitions */
/*********************/

/**	Length of the Viewable area of the screen buffer.
*/
#define u8VIEWABLE_BUFFER_LENGTH		(u8)15  /*MAIN_nSCREEN*/

/**	Number of charachters to be initialized to zeros.
*/
#define u8ZERO_INITIALIZED_CHARS		(u8)15  /*MAIN_nSCREEN*/

/**	Number of colomns for a single charachter on the screen.
*	The number of colomns includes two colomns for space after every charachter.
*/
#define	u8COLOMNS_PER_CHAR				(u8)6

/** Number of colomns of the charachters without the spaces.
*/
#define u8CHAR_COLOMNS_NUMBER           (u8)5

/**	Number of colomns to dump from the front of the queue with each function call.
*		This figure gives the number of colomns to be shifted every time on the screen.
*/
#define u8DUMP_COLOMNS					(u8)1



/*******************/
/*	Local Variables*/
/*******************/


/**	This variable holds number of empty colomns in the buffer. 
*		When this variable reaches seven this means 
*	that a space for a full charachter is now free so the main 
*	function will fill it in.
*/
static u8			u8NumberOfCopiedColomns;

/** Pointer to the next charachter to enter the screen buffer.
*/
static u16         	u16NextCharIndex;

/**	Data structure managing the effect buffer.
*/
static BUF_tstrBuffer		bufEffectBuffer;


/*********************************/
/*	Local Functions' Declaration */
/*********************************/




/***********************************/
/*	External Functions' Definition */
/***********************************/

void LSC_vidInit(void)
{
	u8 u8Iterator;


	/* Initialize the buffer.and attach it to the buffer control structure*/
	BUF_vidInit(&bufEffectBuffer, EFF_au8EffectsBuffer, EFF_nEFFECTS_BUFFER_LENGTH);

	u8NumberOfCopiedColomns		= u8COLOMNS_PER_CHAR;
	
	u16NextCharIndex = TYP_u8ZERO;
	//u8ViewableAreaCounter	= TYP_u8ZERO;


	for	(u8Iterator = TYP_u8ZERO; u8Iterator < u8ZERO_INITIALIZED_CHARS ; u8Iterator++ )
	{
		BUF_u8AddToEnd(&bufEffectBuffer, TYP_u8ZERO);
	}


}

void LSC_vidLeftScrollEffect(void)
{

	
	u8 u8ColomnData;
	u8 u8Iterator;

    BUF_vidDumpFromFront(&bufEffectBuffer, u8DUMP_COLOMNS );

	if ( u8NumberOfCopiedColomns == u8COLOMNS_PER_CHAR)
	{

		u8NumberOfCopiedColomns = TYP_u8ZERO;
	
		u16NextCharIndex = u16GET_NEXT_CHAR();

    }
    
    if ((u8NumberOfCopiedColomns >= u8CHAR_COLOMNS_NUMBER) && (u8NumberOfCopiedColomns <u8COLOMNS_PER_CHAR))
    {
        u8ColomnData = TYP_u8ZERO;
    }
	else
    {
	    u8ColomnData = pgm_read_byte(&(MSG_u8LUT[u16NextCharIndex + (u16)u8NumberOfCopiedColomns]));
    }
    BUF_u8AddToEnd(&bufEffectBuffer, u8ColomnData);

	u8NumberOfCopiedColomns++;


	for (u8Iterator = TYP_u8ZERO; u8Iterator < SCR_u8SCREEN_BUFFER_LENGTH; u8Iterator++)
	{
		
		u8ColomnData = BUF_u8GetAtIndex(&bufEffectBuffer, u8Iterator);
		SCR_vidSetByte(u8Iterator,u8ColomnData);
	
	}
}



/********************************/
/*	Local Functions' Definition */
/********************************/


